<template>
  <div>
    <el-container class="wrap">
      <el-aside width="200px">
        <el-menu
          :default-active="active"
          background-color="#f0846e"
          text-color="white"
          active-text-color="black"
          router
          unique-opened
        >
          <el-menu-item index="/index"
            ><i class="el-icon-message"></i>首页</el-menu-item
          >

          <div v-for="item in user.menus" :key="item.id">
            <!-- 目录 -->
            <el-submenu :index="item.id+''" v-if="item.children">
              <template slot="title"
                ><i :class="item.icon"></i>{{ item.title }}
              </template>
              <el-menu-item v-for="it in item.children" :key="it.id" :index="'/index'+it.url">{{it.title}}</el-menu-item>
            </el-submenu>
            <!-- 菜单 -->
            <el-menu-item v-else :index="'/index'+item.url">{{item.title}}</el-menu-item>
          </div>
          <!-- 
          <el-submenu index="2">
            <template slot="title"
              ><i class="el-icon-message"></i>商城管理</template
            >
            <el-menu-item-group>
              <el-menu-item index="/index/cate">商品分类</el-menu-item>
              <el-menu-item index="/index/specs">商品规格</el-menu-item>
              <el-menu-item index="/index/goods">商品管理</el-menu-item>
              <el-menu-item index="/index/member">会员管理</el-menu-item>
              <el-menu-item index="/index/banner">轮播图管理</el-menu-item>
              <el-menu-item index="/index/seckill">秒杀活动</el-menu-item>
            </el-menu-item-group>
          </el-submenu> -->
        </el-menu>
      </el-aside>


      <el-container>
        <el-header>
          <el-tag class="user">
            欢迎您：{{user.username}}
            <span @click="goOut"> 退 出</span>
          </el-tag>
          
        </el-header>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/index' }"
              >首页</el-breadcrumb-item
            >
            <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- 二级路由出口 放在面包屑之后 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { successAlert } from "../../utils/alert.js";
export default {
  data() {
    return {
      active: "/index",
    };
  },
  methods: {
    ...mapActions({
      asyncChangeUser: "asyncChangeUser",
    }),
    goOut(){
      successAlert("您已退出")
      sessionStorage.removeItem("user");
      this.$router.push("/")
    }
  },
  computed: {
    ...mapGetters({
      user: "user",
    }),
  },
  mounted() {
    this.active = this.$route.path;
  },
};
</script>

<style lang="less" scoped>
@import url("../../less/color.less");
.wrap {
  width: 100vw;
  height: 100vh;
}
.el-header {
  background-color: @color4;
}
.el-aside {
  background-color: @color3;
}
.el-main {
  background-color: @color5;
}
.el-menu i {
  color: white;
}
.user{
  margin-top: 10px;
}
.user span{
  margin-left: 10px;
  cursor: pointer;
  text-decoration: underline;
}
.user span:hover{
  color: brown;
}
</style>